<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加网站</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${global_templets_skin}/systemstyle/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${global_templets_skin}/systemstyle/style/admin.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">网站设置</div>
                <div class="layui-card-body" pad15>

                    <div class="layui-form" wid100 lay-filter="">
                        <div class="layui-form-item">
                            <label class="layui-form-label">网站名称</label>
                            <div class="layui-input-block">
                                <input type="text" name="siteName" value="${site.siteName!}" lay-verify="required" placeholder="网站名称，如：北京某某科技有限公司" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">二级域名</label>
                            <div class="layui-input-block">
                                <div class="layui-input-inline" style="width: 80px;">
                                    <input type="text" name="domain" id="domain" lay-verify="required" value="${site.domain!}" class="layui-input">
                                </div>
                                <div class="layui-input-inline layui-input-company">.97560.com</div>
                                <div class="text-tips" id="domain-tips">PC端可通过浏览器访问。</div>
                            </div>
                        </div>

                        <div class="layui-form-item layui-form-text">
                            <label class="layui-form-label">首页标题</label>
                            <div class="layui-input-block">
                                <textarea name="title" class="layui-textarea" placeholder="建议网站名称加标题不超过30个中文，百度显示30个中文字符，超过30个中文字符的标题就会被省略掉">${site.title!}</textarea>
                            </div>
                        </div>
                        <div class="layui-form-item layui-form-text">
                            <label class="layui-form-label">META关键词</label>
                            <div class="layui-input-block">
                                <textarea name="keywords" class="layui-textarea" placeholder="keywords数量应该控制在0-3个之间，最多不超过5个。如果一个非常专业的网站，设置一个keywords，多个关键词用英文状态 , 号分割">${site.keywords!}</textarea>
                            </div>
                        </div>
                        <div class="layui-form-item layui-form-text">
                            <label class="layui-form-label">META描述</label>
                            <div class="layui-input-block">
                                <textarea name="description" class="layui-textarea"  placeholder="出现核心的关键词，必须完整的出现在描述中。描述长度155个字符。">${site.description!}</textarea>
                            </div>
                        </div>
                        <div class="layui-form-item layui-form-text">
                            <label class="layui-form-label">版权信息</label>
                            <div class="layui-input-block">
                                <textarea name="copyright" class="layui-textarea">${site.copyright!}</textarea>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <input type="hidden" name="id" id="id" value="${site.id!}">
                                <button class="layui-btn" lay-submit lay-filter="addsite">确认保存</button>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>

<script src="${global_templets_skin}/systemstyle/layui/layui.js"></script>
<script>
    layui.config({
        base: '${global_templets_skin}/systemstyle/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'set'], function () {
        var form   = layui.form;
        var $      = layui.jquery;
        var layer  = layui.layer;

        //查询二级域名状态
        $("#domain").on("blur", function(){
            var domain=$("#domain").val();
            var siteId=$("#id").val();
            if(domain.length>0){
                if(/^[0-9a-zA-Z]*$/.test(domain)){
                    $.ajax({
                        url:'/admin/system_site/queryDomain.do',
                        type:'post',
                        dataType: 'json',
                        data: {"domain":domain,"siteId":siteId},
                        success:function(e){
                            if (e.code == "0") {
                                $("#domain-tips").html("可通过这个二级域名访问您的网站");
                                $(this).closest('div').removeClass('has-error').addClass('has-success');
                            }else {
                                $("#domain-tips").html("服务器连接错误请联系管理员");
                                $(this).closest('div').removeClass('has-success').addClass('has-error');
                            }
                        }
                    })
                }else{
                    $("#domain-tips").html("二级域名格式不对");
                    $(this).closest('div').removeClass('has-success').addClass('has-error');
                }
            }else{
                $("#domain-tips").html("二级域名不能为空");
                $(this).closest('div').removeClass('has-success').addClass('has-error');
            }
        });

        form.on('submit(addsite)', function(data) {
            $.ajax({
                url:'/admin/system_site/edit.do',
                type:'post',
                dataType: 'json',
                data: data.field,
                success:function(e){
                    if (e.code == "0") {
                        layer.msg('成功', {icon:1,time:1000},function(){
                            setTimeout('window.location.reload()',1000);
                        });
                    }else {
                        layer.msg('失败');
                    }
                }
            })
            //防止页面跳转
            return false;
        });

    });
</script>
</body>
</html>